package com.tsite.dao.impl;

import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;

import com.tsite.dao.IRoleDAO;
import com.tsite.entity.Role;

@Repository
public class RoleDAO extends GenericDAO<Role> implements IRoleDAO {

	@Override
	public Role findRoleByMatchedName(String roleName) {
		TypedQuery<Role> query = getEntityManager().createNamedQuery("findRoleByMatchedName", Role.class);
		query.setParameter("role", roleName);
		Role role = null;
		try {
			role = query.getSingleResult(); 
		} catch (NoResultException e) {
			role = null;
		}		
		return role;
	}	
}